package pro1.util;

import java.util.ArrayList;
import java.util.List;

public class ListUp {

	
	/**
	  * list分页
	  * @param page 当前页码
	  * @param num 页数
	  * @param list  所有集合
	  * @return
	  * @throws Exception
	  */
	 public static List<Object> page(int page,int num,List<Object> list) throws Exception{
	  List<Object> result = new ArrayList<Object>();
	  if(list != null && list.size() > 0){
	   int allCount = list.size();
	   int pageCount = (allCount + num-1) / num;
	   if(page >= pageCount){
	    page = pageCount;
	   }
	   int start = (page-1) * num;
	   int end = page * num;
	   if(end >= allCount){
	    end = allCount;
	   }
	   for(int i = start; i < end; i ++){
	    result.add(list.get(i));
	   }
	  }
	  return (result != null && result.size() > 0) ? result : null;
	 }
	  
}
